package com.molichuxing.gateway.bff.car.services.Impl;

import com.molichuxing.gateway.bff.car.convertor.Convert;
import com.molichuxing.gateway.bff.car.entity.response.MaintenanceRecordVo;
import com.molichuxing.gateway.bff.car.services.MaintenanceBffService;
import com.molichuxing.gateway.property.CarCheckClientEnum;
import com.molichuxing.services.business.dto.response.MaintenanceRecordBizDto;
import com.molichuxing.services.business.dto.response.UserBizDto;
import com.molichuxing.services.business.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆检验bff
 * @author xuelin yi
 */
@Service("maintenanceBffService")
public class MaintenanceBffServiceImpl implements MaintenanceBffService {

	private static final Logger logger = LoggerFactory.getLogger(MaintenanceBffServiceImpl.class);

	@Resource
	private MaintenanceBizService maintenanceBizService;

	@Resource
	private UserBizService userBizService;



	@Override
	public List<MaintenanceRecordVo> getMaintenanceByCarId(Integer carId) throws Exception{
		List<MaintenanceRecordBizDto> maintenanceRecordList = maintenanceBizService.getMaintenanceByCarId(carId);
		List<MaintenanceRecordVo> result = Convert.toMaintenanceRecordVo(maintenanceRecordList);
		if((null != result)&&(result.size() > 0)) {
			for (MaintenanceRecordVo maintenanceRecordVo : result) {
				//用户
				if (maintenanceRecordVo.getOperationType() == 2) {
					UserBizDto userBizDto = userBizService.getUser(Integer.parseInt(maintenanceRecordVo.getOperationId()));
					if (null != userBizDto) {
						maintenanceRecordVo.setRealName(userBizDto.getRealName());
						maintenanceRecordVo.setUserName(userBizDto.getName());
						maintenanceRecordVo.setUserPhone(userBizDto.getPhone());
						maintenanceRecordVo.setIdNumber(userBizDto.getIdNumber());
					}
				} else {
					maintenanceRecordVo.setUserName(CarCheckClientEnum.MOLI.getName());
				}
			}
		}
		return result;
	}


}
